package com.childenglish.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.List;

/**
 * 角色验证器
 */
public class ValidRoleValidator implements ConstraintValidator<ValidRole, String> {
    
    private static final List<String> VALID_ROLES = Arrays.asList("admin", "parent", "child", "teacher");
    
    @Override
    public void initialize(ValidRole constraintAnnotation) {
        // 初始化方法，可以在这里获取注解参数
    }
    
    @Override
    public boolean isValid(String role, ConstraintValidatorContext context) {
        if (role == null || role.trim().isEmpty()) {
            return false;
        }
        return VALID_ROLES.contains(role.trim().toLowerCase());
    }
}

